<html>
<head><meta charset="utf-8"><title>print inside the compiler · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/print.20inside.20the.20compiler.html">print inside the compiler</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="221339831"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/print%20inside%20the%20compiler/near/221339831" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Elazar Leibovich <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/print.20inside.20the.20compiler.html#221339831">(Jan 01 2021 at 07:12)</a>:</h4>
<p>Can I use print inside the compiler, for debugging?</p>



<a name="221343126"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/print%20inside%20the%20compiler/near/221343126" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/print.20inside.20the.20compiler.html#221343126">(Jan 01 2021 at 08:52)</a>:</h4>
<p>Yes, you can use <code>println!()</code>. However, cargo passes the compiler a flag that causes it to emit error messages in json format. Using <code>println!()</code> will not emit json messages, so cargo will just ignore the lines. If you use <code>eprintln!()</code> however, stderr will be used instead of stdout. Cargo does not expect stderr to contain json messages, but will just pass through everything written to stderr. For this reason, you should use <code>eprintln!()</code> or <code>dbg!()</code> (which also uses stderr) if your rustc build is invoked by cargo.</p>



<a name="221348578"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/print%20inside%20the%20compiler/near/221348578" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/print.20inside.20the.20compiler.html#221348578">(Jan 01 2021 at 11:47)</a>:</h4>
<p>FYI you might also be interested in using <code>debug!()</code> and friends along with <code>RUSTC_LOG</code>, as explained in the <a href="https://rustc-dev-guide.rust-lang.org/compiler-debugging.html#getting-logging-output">guide</a>.</p>



<a name="221348625"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/print%20inside%20the%20compiler/near/221348625" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/print.20inside.20the.20compiler.html#221348625">(Jan 01 2021 at 11:48)</a>:</h4>
<p>This is better than plain <code>println</code> because you can use fancy things like tracing's <a href="https://tracing.rs/tracing/attr.instrument.html"><code>instrument</code></a> attribute which can really help understanding what's happening</p>



<a name="221352928"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/print%20inside%20the%20compiler/near/221352928" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/print.20inside.20the.20compiler.html#221352928">(Jan 01 2021 at 14:01)</a>:</h4>
<p>I really need to learn how tracing works <span aria-label="laughing" class="emoji emoji-1f606" role="img" title="laughing">:laughing:</span></p>



<a name="221361309"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/print%20inside%20the%20compiler/near/221361309" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Eric Huss <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/print.20inside.20the.20compiler.html#221361309">(Jan 01 2021 at 17:52)</a>:</h4>
<p><span class="user-mention silent" data-user-id="133247">bjorn3</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/print.20inside.20the.20compiler/near/221343126">said</a>:</p>
<blockquote>
<p>Using <code>println!()</code> will not emit json messages, so cargo will just ignore the lines.</p>
</blockquote>
<p>Cargo passes stdout as-is, so they should appear.  stdout isn't cached on-disk, which can be a good or bad thing depending on the situation.</p>
<p>Personally I would use the log macros, though.</p>



<a name="221367079"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/print%20inside%20the%20compiler/near/221367079" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Noah Lev <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/print.20inside.20the.20compiler.html#221367079">(Jan 01 2021 at 20:19)</a>:</h4>
<p><span class="user-mention silent" data-user-id="245339">Nadrieril</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/print.20inside.20the.20compiler/near/221348625">said</a>:</p>
<blockquote>
<p>This is better than plain <code>println</code> because you can use fancy things like tracing's <a href="https://tracing.rs/tracing/attr.instrument.html"><code>instrument</code></a> attribute which can really help understanding what's happening</p>
</blockquote>
<p>Wow, I didn't know <code>#[instrument]</code> existed! That looks really helpful :)</p>



<a name="221367399"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/print%20inside%20the%20compiler/near/221367399" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Nadrieril <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/print.20inside.20the.20compiler.html#221367399">(Jan 01 2021 at 20:28)</a>:</h4>
<p>It so good <span aria-label="yum" class="emoji emoji-1f60b" role="img" title="yum">:yum:</span></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>